<template>
    <div>
        <div>
            <el-config-provider :locale="zhCn"> <!--《:locale="zhCn 》设置语言-->

                <el-scrollbar height="70vh">
                    <!-- 调休申请 -->
                    <el-row :gutter="24">
                        <el-col :span="24">
                            <div class="grid-content ep-bg-purple-light" style="padding: 15px 0;">
                                <el-form-item label="调休申请" label-position="top"
                                    :style="{ fontSize: '15px', fontWeight: 'bold', borderBottom: '1px dashed #e4e7ed' }">
                                    <div class="progress-bar">
                                        <div class="progress"></div>
                                    </div>
                                </el-form-item>

                            </div>
                        </el-col>

                        <!--  -->
                        <el-col :span="12">
                            <div class="grid-content ep-bg-purple-light"><el-form-item label="调休单号"
                                    label-position="top">
                                    <el-input :placeholder="vacationApplicationDetails.vacationId || ''"
                                        style="width: 354px;" disabled />
                                </el-form-item>
                            </div>
                        </el-col>
                        <el-col :span="12">
                            <div class="grid-content ep-bg-purple-light"><el-form-item label="申请日期"
                                    label-position="top">
                                    <el-input :placeholder="vacationApplicationDetails.applicationDate || ''"
                                        style="/*width: 260px;*/" disabled />
                                </el-form-item>
                            </div>
                        </el-col>

                        <el-col :span="12">
                            <div class="grid-content ep-bg-purple-light"><el-form-item label="请假类型"
                                    label-position="top">
                                    <el-input :placeholder="vacationApplicationDetails.vacationType || '调休'"
                                        style="/*width: 260px;*/" disabled />
                                </el-form-item>
                            </div>
                        </el-col>
                        <el-col :span="12">
                            <div class="grid-content ep-bg-purple-light"><el-form-item label="姓名" label-position="top">
                                    <el-input :placeholder="user.employeeName || ''" style="/*width: 354px;*/"
                                        disabled />
                                </el-form-item>
                            </div>
                        </el-col>

                        <el-col :span="12">
                            <div class="grid-content ep-bg-purple-light"><el-form-item label="所在部门"
                                    label-position="top">
                                    <el-input :placeholder="user.department.deptName || ''" style="/*width: 260px;*/"
                                        disabled />
                                </el-form-item>
                            </div>
                        </el-col>

                        <el-col :span="24">
                            <div class="grid-content ep-bg-purple-light"><el-form-item label="调休" label-position="top">
                                    <!-- <span style="font-size: 12px;">若调休多日，请按照时段逐一填写。</span> -->

                                    <el-table :data="vacationPage.records || []" border stripe>
                                        <el-table-column type="index" width="50" />
                                        <el-table-column v-for="col in vacation_columns" :prop="col.id" :key="col.id"
                                            :label="col.label" :width="col.width">
                                        </el-table-column>

                                    </el-table>

                                </el-form-item>

                            </div>
                            <div>
                                <el-pagination @current-change="loadVacationApplication" v-model:currentPage="vacationPage.current"
                                    :page-sizes="[2, 4, 6, 8, 10]" :page-size="vacationPage.size" :total="vacationPage.total"
                                    layout="total, prev, pager, next">
                                </el-pagination>
                            </div>
                        </el-col>

                        <!--  -->
                        <el-col :span="24">
                            <!-- 空白分隔区域 -->
                            <div style="height: 10px; border-top: 0px dashed #e4e7ed; margin: 6px 0;"></div>
                        </el-col>

                        <el-col :span="12">
                            <div class="grid-content ep-bg-purple-light"><el-form-item label="合计调休天数"
                                    label-position="top">
                                    <el-input :placeholder="vacationApplicationDetails.totalDuration || '0'"
                                        style="width: 354px;" disabled />
                                </el-form-item>
                            </div>
                        </el-col>
                        <el-col :span="12">
                            <div class="grid-content ep-bg-purple-light"><el-form-item label="调休事由说明"
                                    label-position="top">
                                    <el-input v-model="vacationApplicationDetails.reason" style="width: 633px;"
                                        :rows="6" placeholder="" disabled />
                                </el-form-item>
                            </div>
                        </el-col>
                    </el-row>
                </el-scrollbar>

            </el-config-provider>
        </div>
    </div>
</template>

<script setup>
import { ref, computed, defineProps } from 'vue'
import request from '@/api/request';
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import { ElMessage, ElMessageBox } from 'element-plus'
import router from '@/router';

// 获取session中的用户信息 - 需要解析JSON字符串
let user = JSON.parse(sessionStorage.getItem('user') || '{}');

const props = defineProps({
    vacationApplicationDetails: {
        type: Object,
        default: () => ({})
    }
});

// 调休数据源
const vacationData = ref(props.vacationApplicationDetails.vacationDetails || []);

// 计算合计调休天数
const totalVacationDays = computed(() => {
    if (props.vacationApplicationDetails.vacationDetails) {
        return props.vacationApplicationDetails.vacationDetails.reduce((total, item) => {
            return total + parseFloat(item.duration || 0);
        }, 0);
    }
    return 0;
});

// 请假日期
const vacation_columns = ref([
    { id: 'vacationDate', label: '调休日期' },
    { id: 'vacationPeriod', label: '调休时段' },
    { id: 'duration', label: '调休天数小计' },
    { id: 'attendanceCycle', label: '归属考勤周期' },
])
// 请假日期数据源
const vacationPage = ref({
    current: 1,
    size: 3,
    total: 0,
    records: []
})

let loadVacationApplication = () => {
    request({
        url: "/vacationApplication/vacationDetails",
        method: "get",
        params: {
            current: vacationPage.value.current,
            size: vacationPage.value.size,
            applicationDate: props.vacationApplicationDetails.applicationDate
        }
    }).then(resp => {
        vacationPage.value = resp.data
        console.log(resp.data)

        // 处理每个记录的计算
        vacationPage.value.records.forEach(record => {
            // 计算调休天数小计
            if (record.vacationPeriod === '上午' || record.vacationPeriod === '下午') {
                record.duration = 0.5;
            } else if (record.vacationPeriod === '全天') {
                record.duration = 1;
            } else {
                record.duration = 0;
            }
        });
    })
};

loadVacationApplication();

//日期类型

const isVisible = ref(false)
// 复制添加
const add = () => {
    isVisible.value = true
    router.push('./insert.vue')
}
//修改显示
const EditDisplay = ref(false)
//编辑
const Editor = () => {
    EditDisplay.value = true
}

//删除操作
const open = () => {
    ElMessageBox.confirm(
        '你确定要删除吗?',
        '通知',
        {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'error',
        }
    )
        .then(() => {
            ElMessage({
                type: 'success',
                message: '删除成功',

            })
            emit("ref-table")
        })
        .catch(() => {
            ElMessage({
                type: 'warning',
                message: '取消操作',
            })
        })
}

const closeDialog = () => {
    // 关闭对话框的逻辑应该由父组件控制
}
</script>

<style scoped>
/* 外层容器，可控制整体条的高度、圆角等 */
.progress-bar {
    height: 6px;
    background-color: #ccebf7;
    border-radius: 3px;
    display: flex;
    width: 100%;
    /* 确保进度条容器宽度占满父容器 */
    overflow: hidden;
    /* 防止子元素溢出 */
}

.progress {
    width: 8%;
    height: 10;
    background-color: #61c3ea;
    border-radius: 3px 0 0 3px;
    transition: width 0.3s ease;
    /* 添加宽度变化的过渡效果 */
}

.bottom-submit-bar {
    /* position: fixed; */
    /* 固定定位 */
    bottom: 0;
    /* 靠底部 */
    left: 0;
    width: 100%;
    background-color: #fff;
    /* 背景色，可根据需求调整 */
    border-top: 1px solid #eaeaea;
    /* 顶部边框，与页面区分 */
    padding: 12px 24px;
    /* 内边距，适配截图里的间距风格 */
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    /* 按钮靠左，可根据实际需求调整 */
    z-index: 10;
    /* 提高层级，避免被其他内容覆盖 */
}
</style>